package top.chukongxiang.dubboboot.simple.gateway.oauth2;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

/**
 * 当前登录用户的详细信息
 */
@Component
public class AuthDetail {

    /**
     * 返回认证用户信息详情
     */
    public UserInfo getUserInfo() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return (UserInfo) authentication.getPrincipal();
    }

    /**
     * 获取用户的用户名
     * @return
     */
    public String getAccount() {
        return getUserInfo().getUsername();
    }


}
